package ServletTime;

/**
 * @author 李某
 * * @date 2021/11/20
 * *物有本末，事有终始。知其先后者，则近道矣！
 * *荷花开满池塘的前一天还是半塘荷花半塘云。
 */

// SimpleDateFormat 是一个以语言环境敏感的方式来格式化和解析日期的具体类。
// SimpleDateFormat 允许您选择任何用户定义的日期时间格式化的模式。





import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

    /**
     * Servlet implementation class CurrentDate
     */
    @WebServlet("/CurrentDate")
    public class CurrentDateFormat1 extends HttpServlet {
        private static final long serialVersionUID = 1L;

        public CurrentDateFormat1() {
            super();
        }

        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            response.setContentType("text/html;charset=UTF-8");

            PrintWriter out = response.getWriter();
            String title = "显示当前的日期和时间";
            Date dNow = new Date( );
            SimpleDateFormat ft =
                    new SimpleDateFormat ("yyyy.MM.dd  hh:mm:ss E a ");
            String docType = "<!DOCTYPE html> \n";
            out.println(docType +
                    "<html>\n" +
                    "<head><title>" + title + "</title></head>\n" +
                    "<body bgcolor=\"#f0f0f0\">\n" +
                    "<h1 align=\"center\">" + title + "</h1>\n" +
                    "<h2 align=\"center\">" + ft.format(dNow) + "</h2>\n" +
                    "</body></html>");
        }

    }


